package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.utils.Constants;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.shehuan.statusview.StatusView;
import com.shehuan.statusview.StatusViewConvertListener;
import com.shehuan.statusview.ViewHolder;

import butterknife.BindView;

/**
 * Created by TCL on 2019/4/25.
 * Describe:
 */
public class MultiStatusActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_multi_status;
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_multi_status));
        toolbar.inflateMenu(R.menu.menu_multi_status);
    }

    @Override
    protected boolean isMultiStatusEnabled() {
        return true;
    }

    @Override
    protected void initMultiStatusEvent(final StatusView statusView) {
        statusView.setOnStatusViewConvertListener(Constants.MULTI_STATUS_ERROR, new StatusViewConvertListener() {
            @Override
            public void onConvert(ViewHolder viewHolder) {
                ImageView iv = viewHolder.getView(R.id.iv_error);
                iv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //模拟重试
                        MyToast.toastNormal(MultiStatusActivity.this,"正在重试...");
                        statusView.showContentView();
                    }
                });

            }
        });
    }

    @Override
    protected void setListener() {
        toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.toolbar_content:
                        showMultiStatus(Constants.MULTI_STATUS_NORMAL);
                        break;
                    case R.id.toolbar_loading:
                        // 显示指定索引的状态布局
                        showMultiStatus(Constants.MULTI_STATUS_LOADING);
                        break;
                    case R.id.toolbar_error:
                        showMultiStatus(Constants.MULTI_STATUS_ERROR);
                        break;
                    case R.id.toolbar_nodata:
                        showMultiStatus(Constants.MULTI_STATUS_NODATA);
                        break;
                    case R.id.toolbar_nonet:
                        showMultiStatus(Constants.MULTI_STATUS_NONET);
                        break;
                }
                return true;
            }
        });
    }

}
